package com.ncloud.crm.mapper;

import org.apache.ibatis.annotations.*;

import com.ncloud.crm.entity.order.WorkNodeNetAccess;

import java.util.List;

/**
 * Created by shiqiang on 2017/4/11.
 */
@Mapper
public interface WorkNodeNetAccessMapper {
    @Select(value = { "select a.*,f_get_label('ACCESS_TYPE',a.access_type) as access_type_name"
    		+ " from bs_o_work_net_access a where a.work_id = #{workId}" })
    @Results({ @Result(column = "work_id", property = "workId"), 
    		@Result(column = "modify_tag", property = "modifyTag"),
            @Result(column = "node_id", property = "nodeId"),
            @Result(column = "isp_inst_id", property = "ispInstId"),@Result(column="net_type",property="netType"),
            @Result(column="isp_name",property="ispName"),@Result(column="access_type",property="accessType"),
            @Result(column="isp_width",property="ispWidth"),@Result(column="access_type_name",property="accessTypeName"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
			@Result(column="access_gateway",property="accessGateway"),@Result(column="access_ip_addr",property="accessIpAddr")
    })
    public List<WorkNodeNetAccess> getWorkNodeInterByWorkId(Long workId);
    @Insert(value = "insert into bs_o_work_net_access(work_id,modify_tag,node_id,isp_inst_id,isp_name,access_type,isp_width,net_type,net_name," +
            "begin_date,end_date,update_time,update_user,access_ip_addr,access_gateway) values(#{workId},#{modifyTag},#{nodeId},#{ispInstId}," +
            "#{ispName},#{accessType},#{ispWidth},#{netType},#{netName},#{beginDate},#{endDate},#{updateTime},#{updateUser},#{accessIpAddr},#{accessGateway})")
    public int insertWorkNodeInter(WorkNodeNetAccess workNodeEqpt);
    
	@Select(value = { "select #{workId} as work_id,node_id,isp_inst_id,IFNULL(f_get_label('ISP',isp_name),isp_name) as isp_name,"
			+ " access_type,isp_width,net_type,f_get_label('ACCESS_TYPE',access_type) as access_type_name,access_ip_addr,access_gateway"
			+ " from bs_net_access where node_id = #{nodeId} and NOW() BETWEEN begin_date and end_date"
			+ " and isp_inst_id not in (select isp_inst_id from bs_o_work_net_access where work_id = #{workId} and modify_tag = '3')"
			+ " UNION "
			+ " select work_id,node_id,isp_inst_id,IFNULL(f_get_label('ISP',isp_name),isp_name) as isp_name,access_type,isp_width,"
			+ " net_type,f_get_label('ACCESS_TYPE',access_type),access_ip_addr,access_gateway"
			+ " from bs_o_work_net_access where work_id = #{workId} and modify_tag = '1'" })
    @Results({ @Result(column = "work_id", property = "workId"), 
            @Result(column = "node_id", property = "nodeId"),
            @Result(column = "isp_inst_id", property = "ispInstId"),
            @Result(column="isp_name",property="ispName"),@Result(column="access_type",property="accessType"),
            @Result(column="isp_width",property="ispWidth"),@Result(column="access_type_name",property="accessTypeName"),
			@Result(column="net_type",property="netType"),@Result(column="net_name",property="netName"),
			@Result(column="access_gateway",property="accessGateway"),@Result(column="access_ip_addr",property="accessIpAddr")})
	public List<WorkNodeNetAccess> getNewNodeIntersByWorkId(@Param("workId")Long workId, @Param("nodeId")Long nodeId);
	
}
